package com.blb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blb.entity.Comtype;
import com.blb.entity.ComtypeExample;
import com.blb.entity.ComtypeExample.Criteria;
import com.blb.mapper.ComtypeMapper;
import com.blb.service.IComtypeService;
import com.blb.utils.LayuiPage;
import com.mysql.jdbc.StringUtils;

@Service
public class ComtypeServiceImpl implements IComtypeService {
	@Autowired
	private ComtypeMapper comtypeMapper;
	
	@Override
	public LayuiPage page(int page, int limit,String name) {
		List<Comtype> list = comtypeMapper.page(page, limit, name);
		ComtypeExample comtypeExample = new ComtypeExample();
		if(!StringUtils.isNullOrEmpty(name)){
			Criteria criteria = comtypeExample.createCriteria();
			criteria.andNameLike("%"+name+"%");
		}
		int count = (int) comtypeMapper.countByExample(comtypeExample);
		return new LayuiPage(count, list);
	}

	@Override
	public String add(Comtype comtype) {
		comtypeMapper.insertSelective(comtype);
		return "";
	}
	
	@Override
	public int delete(List<String> ids) {
		ComtypeExample comtypeExample = new ComtypeExample();
		comtypeExample.createCriteria().andIdIn(ids);
		return comtypeMapper.deleteByExample(comtypeExample);
	}

	@Override
	public String update(Comtype comtype) {
		comtypeMapper.updateByPrimaryKeySelective(comtype);
		return "";
	}

}
